//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public abstract class PercentTransform : ColorTransform
    {
        private double val;

        public PercentTransform()
        {
        }

        public PercentTransform(double value)
        {
            val = value;
        }

        protected abstract string XmlName { get; }


        public double Value
        {
            get { return val; }
            set { val = value; }
        }

        public double Ratio
        {
            get { return Value/100000; }
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read(XmlName))
            {
                Value = c.GetDouble("val");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write(XmlName))
            {
                c.SetDouble("val", Value);
            }
        }
    }
}